﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Power.BLL;
using Power.Model;
using JN.Utility;

namespace LogManager
{
    public enum DbLogType
    {
        UserLogOn,
        UserLogOff,
        UserChange,
    }
    public static class DataBaseLogger
    {
        #region property
        private static Sys_logBLL loggerBLL = new Sys_logBLL();
        private static object lockWrite = new object();
        #endregion

        /// <summary>
        /// 记录消息
        /// </summary>
        /// <param name="logType"></param>
        /// <param name="info"></param>
        /// <param name="stationId"></param>
        public static void Write(DbLogType logType, string info, string stationId)
        {
            lock (lockWrite)
            {
                try
                {
                    Sys_log mlog = new Sys_log();
                    mlog.log_info = info;
                    mlog.log_type = logType.ToString();
                    mlog.station_id = stationId;
                    mlog.log_time = DateTime.Now;

                    loggerBLL.Add(mlog);
                }
                catch (Exception ex)
                {
                    SystemLogger.Write(ex);
                }
            }
        }
    }
}
